package com.java.exer1;

public class RegexTest_1 {

    public static void main(String[] args) {
        //西安市车牌
        System.out.println(checkCarNum("陕A·02VC0"));
    }

    /**
     * 检查车牌
     * 第一位必须选择英文字母，后四位（除第zhi四位之外）中任选且必须dao有一位为英文字母，其余三位为阿拉伯数字
     * 英文字母不能选用I、O
     */
    public static boolean checkCarNum(String carNum) {
        //有两个字母
        //首位是字母
        boolean flag1 = carNum.matches("陕[AU]·([A-HJ-NP-Z][A-HJ-NP-Z]\\d{3}|[A-HJ-NP-Z]\\d[A-HJ-NP-Z]\\d{2}|[A-HJ-NP-Z]\\d{2}[A-HJ-NP-Z]\\d|[A-HJ-NP-Z]\\d{3}[A-HJ-NP-Z])");
        //第二位是字母
        boolean flag3 = carNum.matches("陕[AU]·(\\d[A-HJ-NP-Z][A-HJ-NP-Z]\\d{2}|\\d[A-HJ-NP-Z]\\d[A-HJ-NP-Z]\\d|\\d[A-HJ-NP-Z]\\d{2}[A-HJ-NP-Z])");
        //第三位是字母
        boolean flag4 = carNum.matches("陕[AU]·(\\d{2}[A-HJ-NP-Z][A-HJ-NP-Z]\\d|\\d{2}[A-HJ-NP-Z]\\d[A-HJ-NP-Z])");
        //第四位是字母
        boolean flag5 = carNum.matches("陕[AU]·(\\d{3}[A-HJ-NP-Z][A-HJ-NP-Z])");
        //有一个字母
        boolean flag2 = carNum.matches("陕[AU]·([A-HJ-NP-Z]\\d{3}|\\d[A-HJ-NP-Z]\\d{3}|\\d{2}[A-HJ-NP-Z]\\d{2}|\\d{3}[A-HJ-NP-Z]\\d{1}|\\d{4}[A-HJ-NP-Z])");

        return flag1 || flag2 || flag3 || flag4 || flag5;
    }
}
